package routers

import (
	"GoOnlineShopLab/controllers"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/user", &controllers.MainController{})
	beego.Router("/orders", &controllers.MainController{})
	beego.Router("/orders/:order_id([0-9]+)", &controllers.MainController{})
	beego.Router("/user/:user_id([0-9]+)/orders", &controllers.MainController{})
	beego.Router("/user/:user_id([0-9]+)", &controllers.MainController{})

	//namespace路由
	ns := beego.NewNamespace("/api",
		// 获取用户信息
		beego.NSRouter("/user/:user_id([0-9]+)/info", &controllers.MainController{}, "GET:UserInfo"), //注意逗号不要忘记了
		// 用户注册的路由
		beego.NSRouter("/user/register", &controllers.MainController{}, "POST:UserRegister"),

		beego.NSNamespace("/order",
			//获取某个订单信息
			beego.NSRouter("/:id([0-9]+)", &controllers.MainController{}),
			//获取所有订单的信息
			beego.NSRouter("/", &controllers.MainController{}),
			//删除一个订单
			beego.NSRouter("/delete", &controllers.MainController{}),
		),

		beego.NSCond(func(ctx *context.Context) bool {
			//没有登录，不能访问啊
			return true
		}),
		beego.NSNamespace("good",
			beego.NSRouter("/:id([0-9]+)/like", &controllers.MainController{}),
		),
	)
	//注册 namespace
	beego.AddNamespace(ns)
}
